{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Visualize Proba-V NDVI Comparison\n",
    "\n",
    "**Author:** René Kopeinig<br>\n",
    "**Description:** Comparison on Proba-V NDVI (Normalized Difference Vegetation Index) Imagery with help of Google Earth Engine Python API. One NDVI is derived on the fly, the other one is the actual NDVI band provided by Proba-V."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import Image\n",
    "import ee\n",
    "ee.Initialize()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Load Proba-V image collection"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "probav = ee.ImageCollection('VITO/PROBAV/C1/S1_TOC_100M')\n",
    "\n",
    "# Reduce image collection to mean\n",
    "probav_mean = probav.mean()\n",
    "\n",
    "# Set location to Europe (Proba-V Footprint: X18Y02) \n",
    "point = ee.Geometry.Point(6.134136, 49.612485)\n",
    "luxembourg = point.buffer(50000).bounds().getInfo()['coordinates']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Calculate and plot Proba-V NDVI \n",
    "This example is not using the NDVI band, instead it will be calculated from NIR and RED band."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<img src=\"https://earthengine.googleapis.com/api/thumb?thumbid=ffce95d5b5fdbfba53422752ba78e4fd&token=3197f34ce2c16a987bee2de876ce8d2d\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ndvi = probav_mean.normalizedDifference([\"NIR\", \"RED\"])\n",
    "Image(url=ndvi.getThumbUrl({\n",
    "    'region':luxembourg,\n",
    "    'min':-0.5,\n",
    "    'max':0.5,\n",
    "    'palette':['ffffe5','f7fcb9','d9f0a3','addd8e','78c679','41ab5d','238443','006837','004529']\n",
    "}))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Plot Proba-V NDVI \n",
    "This example is using the NDVI band."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<img src=\"https://earthengine.googleapis.com/api/thumb?thumbid=a044b82a11084123385a467d3c7ed5d1&token=0745e8a465427d4ed4f065877426f5ac\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Image(url=probav_mean.getThumbUrl({\n",
    "    'region':luxembourg,\n",
    "    'min':0,\n",
    "    'max':255,\n",
    "    'bands':['NDVI'],\n",
    "    'palette':['ffffe5','f7fcb9','d9f0a3','addd8e','78c679','41ab5d','238443','006837','004529']\n",
    "}))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
